<?php

namespace Trawind\Remotes\Repositories\Sale\Sales;

use Trawind\Remotes\BaseRepository;
use Trawind\Basics\Enums\ServiceDomain;
use Trawind\Remotes\Contracts\Repositories\Sale\Sales\OrdersRepository;

/**
 * Class OrdersRepositoryEloquent.
 *
 * @package namespace Trawind\Remotes\Repositories\Sale\Sales;
 */
class OrdersRepositoryEloquent extends BaseRepository implements OrdersRepository
{

    public $baseRoute='/sale/orders';

    /**
     * OrdersRepositoryEloquent constructor.
     */
    public function __construct()
    {
        $this->domain = ServiceDomain::SALE_DOMAIN();
    }


    /**
     * Retrieve all data of repository
     *
     * @param array $columns
     *
     * @return mixed
     */
    public function all($columns = ['*'])
    {
        return $this->setUrl($this->baseRoute)->result();
    }



    /**
     * Find data by id
     *
     * @param       $id
     * @param array $columns
     *
     * @return mixed
     */
    public function find($id, $columns = ['*'])
    {
        return $this->setUrl($this->baseRoute.'/'.$id)->result();
    }




    /**
     * Save a new entity in repository
     *
     * @param array $attributes
     *
     * @return mixed
     */
    public function create(array $attributes)
    {
        return $this->setUrl($this->baseRoute)
            ->setClientOptions(['form_params' => $attributes])
            ->result('POST');
    }



    /**
     * Update a entity in repository by id
     *
     * @param array $attributes
     * @param       $id
     *
     * @return mixed
     */
    public function update(array $attributes, $id)
    {
        return $this->setUrl($this->baseRoute.'/'.$id)
            ->setClientOptions(['form_params' => $attributes])
            ->result('PUT');
    }

    /**
     * Update a entity in repository by id
     *
     * @param array $attributes
     * @param       $id
     *
     * @return mixed
     */
    public function batchDelete(array $attributes)
    {
        return $this->setUrl($this->baseRoute)
            ->setClientOptions(['form_params' => $attributes])
            ->result('DELETE');
    }

    public function fulfillmentNotification(array $param)
    {
        return $this->setUrl($this->baseRoute . '/receipt_quantity')
            ->setClientOptions(['form_params' => $param])
            ->result('POST');
    }

    public function fulfillmentNoticeNotification(array $param)
    {
        return $this->setUrl($this->baseRoute . '/frozen_quantity')
            ->setClientOptions(['form_params' => $param])
            ->result('POST');
    }

    public function invoiceNotification(array $param)
    {
        return $this->setUrl($this->baseRoute . '/receive_invoice')
            ->setClientOptions(['form_params' => $param])
            ->result('POST');
    }

    public function collectionNotification(array $param)
    {
        return $this->setUrl($this->baseRoute . '/receive_collection')
            ->setClientOptions(['form_params' => $param])
            ->result('POST');
    }
}
